package huawei.android.widget.DecouplingUtil;

import android.util.Log;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectUtil {
    private static final String TAG = "ReflectUtil";

    public static void setObject(String str, Object obj, Object obj2, Class<?> cls) {
        if (obj == null) {
            Log.w(TAG, "reflect setObject instance is null");
            return;
        }
        try {
            Field declaredField = cls.getDeclaredField(str);
            declaredField.setAccessible(true);
            declaredField.set(obj, obj2);
        } catch (NoSuchFieldException e) {
            Log.e(TAG, "no field in reflect " + str + " in set object");
        } catch (SecurityException e2) {
            Log.e(TAG, "SecurityException in reflect " + str + " in set object");
        } catch (IllegalArgumentException e3) {
            Log.e(TAG, "IllegalArgumentException in reflect " + str + " in set object");
        } catch (IllegalAccessException e4) {
            Log.e(TAG, "IllegalAccessException in reflect " + str + " in set object");
        }
    }

    public static Object getObject(Object obj, String str, Class<?> cls) {
        Object obj2 = null;
        if (obj == null) {
            Log.w(TAG, "reflect getObject instance is null");
        } else {
            try {
                Field declaredField = cls.getDeclaredField(str);
                declaredField.setAccessible(true);
                obj2 = declaredField.get(obj);
            } catch (NoSuchFieldException e) {
                Log.e(TAG, "no field in reflect " + str + " in get object");
            } catch (IllegalAccessException e2) {
                Log.e(TAG, "IllegalAccessException in reflect " + str + " in get object");
            }
        }
        return obj2;
    }

    public static Object callMethod(Object obj, String str, Class[] clsArr, Object[] objArr, Class<?> cls) {
        Object obj2 = null;
        if (obj == null) {
            Log.w(TAG, "reflect callMethod instance is null");
        } else {
            try {
                Method declaredMethod = cls.getDeclaredMethod(str, clsArr);
                declaredMethod.setAccessible(true);
                obj2 = declaredMethod.invoke(obj, objArr);
            } catch (NoSuchMethodException e) {
                Log.e(TAG, "there is no " + str + "method");
            } catch (IllegalArgumentException e2) {
                Log.e(TAG, "IllegalArgumentException in reflect call " + str);
            } catch (IllegalAccessException e3) {
                Log.e(TAG, "IllegalAccessException in reflect call " + str);
            } catch (InvocationTargetException e4) {
                Log.e(TAG, "InvocationTargetException in reflect call " + str);
            }
        }
        return obj2;
    }

    public static int getInternalId(String str, String str2) {
        try {
            Field field = Class.forName("com.android.internal.R$" + str).getField(str2);
            field.setAccessible(true);
            return field.getInt(null);
        } catch (ClassNotFoundException e) {
            Log.e(TAG, "getInternalId: com.android.internal.R." + str + " not found");
            return 0;
        } catch (NoSuchFieldException e2) {
            Log.e(TAG, "getInternalId: com.android.internal.R." + str + "." + str2 + " not found");
            return 0;
        } catch (IllegalAccessException e3) {
            Log.e(TAG, "getInternalId: IllegalAccessException of com.android.internal.R." + str + "." + str2);
            return 0;
        }
    }
}
